﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.DreamTour.Core;
using ZhouYu.DreamTour.DAL.IRepository;
using ZhouYu.DreamTour.Model;

namespace ZhouYu.DreamTour.DAL.Repository
{
    public class GroupRepository:IGroupRepository
    {
        /// <summary>
        /// 旅游团购信息展示
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public List<Tour> GetTourList()
        {
            //sql语句
            string sql = "SELECT * from Tour";
            //拼接sql语句
            sql += " limit 0,9";
            //调用查询集合方法
            List<Tour> tourLists = DapperHelper<Tour>.QueryList(sql, null);
            return tourLists;
        }


        /// <summary>
        /// 旅游团购图片展示
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public List<TourPicture> GetTourPictureList()
        {
            //sql语句
            string sql = "SELECT * FROM TourPicture";
            //调用查询集合方法
            List<TourPicture> tourpictureLists = DapperHelper<TourPicture>.QueryList(sql, null);
            return tourpictureLists;
        }


       /// <summary>
       /// 根据Id获取旅游团购详情信息
       /// </summary>
       /// <param name="TourId"></param>
       /// <returns></returns>
        public TourDetailRelation GetTourDetailInfoById(int TourId)
        {
            //sql语句
            string sql = "SELECT Title,TourId,Tour_Desc,Price,Discount,DiscountPrice,StartPlace,EndPlace,TourDays,TourType,StartTime,EndTime,RemanentDays from tour WHERE TourId = @TourId";
            //创建一个旅游团购详情信息关联类对象
            TourDetailRelation tourDetailRelation= new TourDetailRelation();
            tourDetailRelation.TourId = TourId;
            //调用查询方法
            return DapperHelper<TourDetailRelation>.QuerySingleOrDefault(sql, tourDetailRelation);
        }


        /// <summary>
        /// 根据订单类型和团购名称来获取人数
        /// </summary>
        /// <param name="TourId"></param>
        /// <returns></returns>
        public int GetCount(string Title)
        {
            //sql语句
            string sql = "SELECT COUNT(1) from orderinfo WHERE Order_ProInfo=@Order_ProInfo AND Order_Type='团购'";
            //创建一个订单对象
            OrderInfo order = new OrderInfo();
            order.Order_ProInfo = Title;
            //调用查询数量方法
            return Convert.ToInt32(DapperHelper<Tour>.ExecuteScalar(sql, order));
        }


        #region 查询旅游团购的出发城市
        /// <summary>
        /// 查询旅游团购的出发城市
        /// </summary>
        /// <param name="TourId"></param>
        /// <returns></returns>
        public List<Tour> CheckAllStartPlace()
        {
            //sql语句
            string sql = "SELECT StartPlace from tour";           
            //调用查询集合方法
            return DapperHelper<Tour>.QueryList(sql,null);
        }
        #endregion


    }
}
